﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SuperLauncher
{
    public partial class InstallPage : UserControl
    {
        public InstallPage()
        {
            InitializeComponent();

            if (System.Environment.OSVersion.Platform == PlatformID.Win32NT
                && System.Environment.OSVersion.Version.Major >= 6
                && System.Environment.OSVersion.Version.Minor >= 1)
            {
                this.btnInstall.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                this.txtSystem.Visibility = System.Windows.Visibility.Visible;
            }

            this.btnInstall.Click += new RoutedEventHandler(btnInstall_Click);

            if (Application.Current.InstallState == InstallState.NotInstalled)
            {
                this.btnInstall.IsEnabled = true;
            }
            else
            {
                this.btnInstall.IsEnabled = false;
                this.btnInstall.Content = "已经成功安装便捷启动器";
            }
        }

        void btnInstall_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.InstallState == InstallState.NotInstalled)
            {
                Application.Current.Install();
                Application.Current.InstallStateChanged += new EventHandler(Current_InstallStateChanged);
            }

            this.btnInstall.IsEnabled = false;
            this.btnInstall.Content = "正在安装便捷启动器...";
        }

        void Current_InstallStateChanged(object sender, EventArgs e)
        {
            this.btnInstall.IsEnabled = false;
            if (Application.Current.InstallState == InstallState.Installed)
            {
                this.btnInstall.Content = "已经成功安装便捷启动器";
            }
            else if (Application.Current.InstallState == InstallState.NotInstalled)
            {
                this.btnInstall.IsEnabled = false;
                this.btnInstall.Content = "点击安装到我的电脑";
            }
        }
    }
}
